﻿<div [@routerTransition]>

    <div class="m-subheader">
        <div class="row align-items-center">
            <div class="mr-auto col-auto">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    <span>{{"Roles" | localize}}</span>
                </h3>
                <span class="m-section__sub">
                    {{"RolesHeaderInfo" | localize}}
                </span>
            </div>
            <div class="col text-right mt-3 mt-md-0">
                <button (click)="createRole()" *ngIf="'Pages.Administration.Roles.Create' | permission" class="btn btn-primary"><i class="fa fa-plus"></i> {{"CreateNewRole" | localize}}</button>
            </div>
        </div>
    </div>

    <div class="m-content">
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__body">
                <div class="m-form m-form--label-align-right">
                    <div class="row m--margin-bottom-10">
                        <div class="col-xl-6">
                            <div class="form-group">
                                <permission-combo name="permissionFilter" [(ngModel)]="selectedPermission"></permission-combo>
                            </div>
                        </div>
                        <div class="col-xl-6 text-right">
                            <button name="RefreshButton" class="btn btn-metal" (click)="getRoles()"><i class="la la-refresh"></i> {{'Refresh' | localize}}</button>
                        </div>
                    </div>
                </div>
                <div class="row align-items-center">
                    <!--<Primeng-TurboTable-Start>-->
                    <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                        <p-table #dataTable
                                 (onLazyLoad)="getRoles()"
                                 [value]="primengTableHelper.records"
                                 rows="{{primengTableHelper.defaultRecordsCountPerPage}}"
                                 [paginator]="false"
                                 [lazy]="true"
                                 [responsive]="primengTableHelper.isResponsive">

                            <ng-template pTemplate="header">
                                <tr>
                                    <th style="width: 130px" [hidden]="!isGrantedAny('Pages.Administration.Roles.Edit', 'Pages.Administration.Roles.Delete')">{{'Actions' | localize}}</th>
                                    <th>{{'RoleName' | localize}}</th>
                                    <th>{{'CreationTime' | localize}}</th>
                                </tr>
                            </ng-template>

                            <ng-template pTemplate="body" let-record="$implicit">
                                <tr>
                                    <td [hidden]="!isGrantedAny('Pages.Administration.Roles.Edit', 'Pages.Administration.Roles.Delete')">
                                        <div class="btn-group dropdown" dropdown>
                                            <button dropdownToggle class="dropdown-toggle btn btn-primary btn-sm dropdown-toggle">
                                                <i class="fa fa-cog"></i><span class="caret"></span> {{"Actions" | localize}}
                                            </button>
                                            <ul class="dropdown-menu" *dropdownMenu>
                                                <li>
                                                    <a href="javascript:;" *ngIf="'Pages.Administration.Roles.Edit' | permission"
                                                       (click)="createOrEditRoleModal.show(record.id)">{{'Edit' | localize}}</a>
                                                </li>
                                                <li>
                                                    <a href="javascript:;" *ngIf="!record.isStatic && ('Pages.Administration.Roles.Delete' | permission)"
                                                       (click)="deleteRole(record)">{{'Delete' | localize}}</a>
                                                </li>
                                                <li>
                                                    <a href="javascript:;" *ngIf="entityHistoryEnabled"
                                                       (click)="showHistory(record)">{{'History' | localize}}</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{'RoleName' | localize}}</span>
                                        <span>
                                            {{record.displayName}}
                                            <span *ngIf="record.isStatic"
                                                  class="m-badge m-badge--brand m-badge--wide"
                                                  data-toggle="tooltip"
                                                  title="{{'StaticRole_Tooltip' | localize}}"
                                                  data-placement="top">
                                                {{'Static' | localize}}
                                            </span>
                                            <span *ngIf="record.isDefault"
                                                  class="m-badge m-badge--metal m-badge--wide"
                                                  data-toggle="tooltip"
                                                  title="{{'DefaultRole_Description' | localize}}"
                                                  data-placement="top">
                                                {{'Default' | localize}}
                                            </span>
                                        </span>
                                    </td>
                                    <td>
                                        <span class="ui-column-title">{{'CreationTime' | localize}}</span>
                                        {{record.creationTime | momentFormat:'L'}}
                                    </td>
                                </tr>
                            </ng-template>
                        </p-table>
                        <div class="primeng-no-data" *ngIf="primengTableHelper.totalRecordsCount == 0">
                            {{'NoData' | localize}}
                        </div>
                        <div class="ui-table-footer">
                        </div>
                    </div>
                    <!--<Primeng-TurboTable-End>-->
                </div>
            </div>
        </div>
    </div>

    <createOrEditRoleModal #createOrEditRoleModal (modalSave)="getRoles()"></createOrEditRoleModal>
    <entityTypeHistoryModal #entityTypeHistoryModal></entityTypeHistoryModal>
</div>
